var qrcodeParm="";
var userRecommendId = "";
$(function () {
    extension()
    //用户推荐码
    var qrCode = GetQueryString("recommendId")
    var type= GetQueryString("type")
    if (userRecommendId==-1) {
        //接受邀请用户
        accept(type)
        if(type!=undefined&&type!=null&&type!=""){
            qrcodeParm = getContextPath()+"/register.html?recommendId=" + qrCode+"&type="+type
        }else{
            qrcodeParm = getContextPath()+"/register.html?recommendId=" + qrCode
        }

    } else if(userRecommendId!=-1&&userRecommendId!=qrCode){
        //推荐给已经注册的用户
        friends(type);
    }else{
        //推荐给自己
        img(type)
    }
    $("#copy").click(function(){
    	 var input = document.getElementById("url");
	   	 input.select();
	   	 document.execCommand("copy"); 
	   	 $("#alert1").modal()
    })
})

/**
 * 推荐用户
 * @param imgId
 */
function img(type) {
    var html = ""
        html = "<iframe src=\"https://c.xiumi.us/stage/v5/2NnvH/87148172\" width=\"100%\" height=\"100%\" frameborder=\"0\">"
    $("#iframe").append(html)
    //获取本页面的url
    var url = window.location.href
    //分享链接
    $("#url").val(url);
}

/**
 * 接受邀请
 */
function accept(type) {
    var html = ""
    html = "<iframe src=\"https://c.xiumi.us/stage/v5/2NnvH/87148172\" width=\"100%\" height=\"100%\" frameborder=\"0\">"
    $("#iframe").append(html)
    $("#qrcode").html("<span onclick='redirect()' style='width:100%;background:#fff;height:40px;line-height:40px;text-align:center;display:inline-block;position:fixed;bottom:0;'>接受邀请,立即注册<span/>");
}
//friends
function friends(type) {
    var html = ""
        html = "<iframe src=\"https://c.xiumi.us/stage/v5/2NnvH/87148172\" width=\"100%\" height=\"100%\" frameborder=\"0\">"
    $("#iframe").append(html)
    //获取本页面的url
    var url = getContextPath()+"/personal/extensionSale.html?recommendId=" + userRecommendId;
    //分享链接
    $("#friends").html("你已是注册用户,复制链接分享给好友进行推广:");
    $("#url").val(url);
}
/**
 * 跳转到注册页面
 */
function redirect() {
    window.location.href = qrcodeParm
}

function extension() {
    slf.ajax({
        url: '/extension',
        type: 'post',
        async: false,
        success: function (data) {
                userRecommendId=data
        }
    })
}
